<template>
  <div class="layout-header-container">
    <!-- 左侧 logo 和 标题区域 -->
    <div class="layout-header-left">
      <!-- logo -->
      <div class="header_logo">
        <img src="/src/assets/images/logo.png" alt="" />
        <span>社区老年人健康管理系统</span>
      </div>
    </div>
    <!-- 右侧按钮区域 -->
    <div class="layout-header-right">
      <div class="avatar">
        <div @click="goIndex" class="rectangle">你好,{{ userInfo.name }}</div>
        <div class="circular">
          <div class="Small_circle">
            <img :src="userInfo.avatar" alt="" />
          </div>
        </div>
      </div>
      <div class="btn">
        <a-popconfirm
          title="确定退出登录吗？"
          ok-text="确定"
          cancel-text="取消"
          @confirm="onLogout"
        >
          <LogoutOutlined />
        </a-popconfirm>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { LogoutOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { logout } from '@/api/User/api'
import { useRouter } from 'vue-router'
import { ref } from 'vue'

const router = useRouter()

const userInfo = ref<any>(
  JSON.parse(localStorage.getItem('employeeInfo') || '')
)

const onLogout = async () => {
  // await logout()
  localStorage.removeItem('authorityToken')
  localStorage.removeItem('employeeInfo')
  router.push('/login')
  // message.success('成功退出')
  router.go(0)
}

const goIndex = () => {
  router.push('/index')
}
</script>

<style lang="less" scoped>
.layout-header-container {
  height: 60px;
  border-bottom: 1px solid #eaeaea;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.5rem;
  background-color: #fff;
  box-shadow: 8px 8px 16px 2px #eee;
  .layout-header-left {
    display: flex;
    align-items: center;
    color: black;
    font-size: 24px;
    .header_logo {
      img {
        width: 50px;
        height: 50px;
      }
      span {
        font-family: '楷体';
        font-weight: 800;
      }
    }
  }
}

.layout-header-left-img {
  height: 50px;
}
.layout-header-right {
  // width: 30%;
  display: flex;
  align-items: center;
  .avatar {
    margin-right: 5px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    .rectangle {
      width: 160px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      background: #f5b017;
      position: absolute;
      top: 0;
      right: 16px;
      border-radius: 10px;
      color: #fff;
    }
    .circular {
      width: 40px;
      height: 40px;
      position: relative;
      border-radius: 50%;
      background: #fff;
      // z-index: -1;
      .Small_circle {
        width: 30px;
        height: 30px;
        overflow: hidden;
        border-radius: 50%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: #5480ef;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }

  .btn {
    transform: rotate(-90deg);
    cursor: pointer;
    margin-right: 15px;
  }
}
</style>
